/**
 * \file
 * \author  michal.nezerka@gmail.com
 * \brief   Implementation of Gpx class and all related classes
 */

//#include <wx/filename.h>
#include <wx/xml/xml.h>

#include "exception.h"
#include "gpx.h"

using namespace wildwood;

Gpx::Gpx()
{
    
}

Gpx::~Gpx()
{

}

void Gpx::saveToFile(wxString path)
{
    wxXmlDocument doc;
    wxXmlNode *rootNode = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("gpx"));

    doc.SetRoot(rootNode);

    if (!doc.Save(path))
        throw Exception(wxT("Error saving gpx"));
}

void Gpx::loadFromFile(wxString path)
{
    // load and parse GPX XML file
    wxXmlDocument doc;
    if (!doc.Load(path))
        throw Exception(wxT("Error loading gpx"));

    // get and check root element
    wxXmlNode *rootNode = doc.GetRoot();

    if (rootNode->GetName() != wxT("gpx"))
        throw Exception(wxT("Invalid root XML element (expected: gpx)"));


}
